package Link;

import org.w3c.dom.Node;

import java.util.LinkedList;
import java.util.Queue;

public class BM15 {
    public class ListNode {
        int val;
        BM13.ListNode next = null;
        public ListNode(int val) {
            this.val = val;
        }
    }

    //删除有序链表中重复的元素-1
    public ListNode deleteDuplicates (ListNode head) {
        if (head == null) {
            return null;
        }
        ListNode cur = head;

        while (cur != null && cur.next != null) {
            if (cur.val == cur.next.val) {
                cur.next = cur.next.next;
            }else {
                cur = cur.next;
            }
        }
        return head;
    }

    //删除有序链表中重复的元素-2
    public ListNode deleteDuplicates01 (ListNode head) {
        if (head == null) {
            return null;
        }
        ListNode res = new ListNode(0);
        res.next = head;
        ListNode cur = res;

        while (cur.next != null && cur.next.next != null) {
            if (cur.next.val == cur.next.next.val) {
                int temp = cur.next.val;
                while (cur.next != null && cur.next.val == temp) {
                    cur.next = cur.next.next;
                }
            }else {
                cur = cur.next;
            }
        }
        return res.next;
    }
}
